<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class MY_Form_validation extends CI_Form_validation
{

    /*public function __construct()
    {
        parent::__construct();
    }*/

    public function not_empty($value)
    {
        $ret =  preg_match("/^\S+$/",$value) ? TRUE:FALSE;
        return $ret;
    }

    public function valid_mobile_phone($mobile)
    {
        return $mobile!='' && ( !preg_match("/^1[0-9]{10}$/",$mobile)) ? FALSE : TRUE;
    }

    public function valid_password($password)
    {
        ///\s|^[\d]{8,16}$|^[a-zA-Z]{8,16}$/
        //return $password !='' && ( preg_match("/\s|^[\d]{8,16}$|^[a-zA-Z]{8,16}$/",$password)) ? FALSE : TRUE;
        //$preg = '/(?!^\\d+$)(?!^[a-zA-Z]+$)(?!^[_#@]+$).{8,16}/';
        //$preg = '/^(?![a-z]+$)(?![A-Z]+$)(?!\d+$)[a-zA-Z0-9]{8,16}$/';
        //$preg = '/^(?![a-z]+$)(?![A-Z]+$)(?!\d+$)[a-zA-Z0-9~!@#$%^&\*\(\)_\+|\-\=\\`\[\]\{\};\':\"<>\?,.\/]{8,16}$/';
        $preg = '/^(?![a-z]+$)(?![A-Z]+$)(?![0-9]+$)[a-zA-Z0-9]{8,16}$/';
        return preg_match($preg,$password) ? TRUE : fALSE;
    }
    /**
     *::验证密码是否符合（不能全为数字或者英文，字数不能少于8字符，并且不能多于16个字符）并返回相应的错误代码
     **/
    public function new_valid_password($password)
    {

        //判断有沉余，可以只用正则判断。
        //判断是否为空
        if(empty($password))
        {
            return 5003;
        }
        //判断长度是否够
        if(strlen($password)<8 || strlen($password)>16)
        {
            return 5022;
        }
        //判断是否全为数字
        if(is_numeric($password))
        {
            //return $this->common_response(5020);
            return 5020;
        }
        //判断是否全为英文字母
        if(preg_match("/^[a-zA-Z\s]+$/",$password))
        {

            return 5021;
        }
        if(preg_match('/^(?![a-z]+$)(?![A-Z]+$)(?![0-9]+$)[a-zA-Z0-9]{8,16}$/',$password))
        {
            return 0;
        }
        else
        {
            return 5019;
        }

    }


    public function get_property($key)
    {
        return $this->$key;
    }

}

/* End of file MY_Form_validation.php */
/* Location: ./application/libraries/MY_Form_validation.php */